home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / DR1.#1 PPC C⁄C++ ƒ / C++ Runtime ƒ / Startup.c < prev   
C/C++ Source or Header  |  1994-01-31  |  2KB  |  111 lines

  1.  
  2. /*
  3.  *    Startup.c        -    Default init/startup/termination routines for Metrowerks C++ (PowerPC)
  4.  *
  5.  *    Copyright © 1993 metrowerks inc. All Rights Reserved.
  6.  *
  7.  */
  8.  
  9. #include <Quickdraw.h>
  10.  
  11.  
  12.     /*    public data        */
  13.  
  14. QDGlobals qd;                        /*    define the Quickdraw globals here!    */
  15. char __exit_abort;                    /*    TRUE => skip __exit_proc and destructors    */
  16. void (*__exit_proc)(void);            /*    called when program terminates but before destructors    */
  17.  
  18.  
  19.      /*    external references    */
  20.  
  21. extern int main(int argc, char **argv);
  22. extern void __destroy_global_chain(void);
  23.  
  24.  
  25.     /*    prototypes    */
  26.  
  27. void __sinit(void);
  28. int __initialize(void);
  29. void __start(void);
  30. void __terminate(void);
  31.  
  32.  
  33. /*
  34.  *    __sinit        -    stub for static initialization of C++ objects
  35.  *
  36.  *    The linker replaces the contents of this module with something of the form:
  37.  *
  38.  *            mflr    r0
  39.  *            stw        r0,8(sp)
  40.  *            stwu    sp,-64(sp)
  41.  *            bl        __sinit_<file1>_1
  42.  *            bl        __sinit_<file1>_2
  43.  *            ...
  44.  *            bl        __sinit_<file2>_1
  45.  *            bl        __sinit_<file2>_2
  46.  *            ...
  47.  *            bl        __sinit_<fileN>_1
  48.  *            bl        __sinit_<fileN>_2
  49.  *            ...
  50.  *            addi    sp,sp,64
  51.  *            lwz        r0,8(sp)
  52.  *            mtlr    r0
  53.  *            blr
  54.  */
  55.  
  56. void __sinit(void)
  57. {
  58. }
  59.  
  60.  
  61. /*
  62.  *    __initialize    -    Default initialization routine for Metrowerks C++ (PowerPC)
  63.  *
  64.  *    This routine should be specified as the PEF initialization routine in the container
  65.  *    for any application or shared library. It ensures that all C++ static objects are
  66.  *    properly initialized, and returns noErr to the Code Fragment Manager.
  67.  *
  68.  */
  69.  
  70. int __initialize(void)
  71. {
  72.     __sinit();
  73.     return(0);    /*    noErr    */
  74. }
  75.  
  76.  
  77. /*
  78.  *    __start    -    Default startup routine for Metrowerks C++ (PowerPC)
  79.  *
  80.  *    This routine should be specified as the PEF main routine in the container
  81.  *    for any application. It sets up default values for 'argc' and 'argv' and
  82.  *    calls 'main'.
  83.  *
  84.  */
  85.  
  86. void __start(void)
  87. {
  88.     char *argv = 0;
  89.     
  90.     main(0, &argv);
  91. }
  92.  
  93.  
  94. /*
  95.  *    __terminate    -    Default termination routine for Metrowerks C++ (PowerPC)
  96.  *
  97.  *    This routine should be specified as the PEF termination routine in the container
  98.  *    for any application or shared library. It calls the __exit_proc which handles
  99.  *    atexit() routines and ensures that all C++ static objects are properly destroyed.
  100.  *
  101.  */
  102.  
  103. void __terminate(void)
  104. {
  105.     if (!__exit_abort) {
  106.         if (__exit_proc)
  107.             (*__exit_proc)();
  108.         __destroy_global_chain();
  109.     }
  110. }
  111.